<?php

namespace App\Library;

class Helper
{
    /**
     * @param $status
     * @param $iv_type
     * @return string
     *
     * 根据逆变器状态吗和逆变器类型把10进制状态码翻译成中文
     */
    public static function transError($status, $iv_type)
    {
//        $status_hex = dechex($status);
        $status_hex = $status;
        $status_label = '未知';
        if($iv_type == 10) {
            switch ($status_hex) {
                case '0000':
                    $status_label = '正常运行';
                    break;
                case '0001':
                    $status_label = '正常运行';
                    break;
                case '0002':
                    $status_label = '等待中';
                    break;
                case '0003':
                    $status_label = '初始化';
                    break;
                case '0004':
                    $status_label = '控制开关';
                    break;
                case '1010':
                    $status_label = '电网过压';
                    break;
                case '1011':
                    $status_label = '电网欠压';
                    break;
                case '1012':
                    $status_label = '电网过频';
                    break;
                case '1013':
                    $status_label = '电网欠频';
                    break;
                case '1014':
                    $status_label = '电网阻抗过大';
                    break;
                case '1015':
                    $status_label = '无电网';
                    break;
                case '1016':
                    $status_label = '电网不平衡';
                    break;
                case '1017':
                    $status_label = '电网频率抖动';
                    break;
                case '1018':
                    $status_label = '电网过流';
                    break;
                case '1020':
                    $status_label = '直流过压';
                    break;
                case '1021':
                    $status_label = '直流母线过压';
                    break;
                case '1022':
                    $status_label = '直流母线不均压';
                    break;
                case '1023':
                    $status_label = '直流母线欠压';
                    break;
                case '1024':
                    $status_label = '直流母线不均压';
                    break;
                case '1025':
                    $status_label = '直流A路过流';
                    break;
                case '1026':
                    $status_label = '直流B路过流';
                    break;
                case '1027':
                    $status_label = '直流输入扰动';
                    break;
                case '1030':
                    $status_label = '电网扰动';
                    break;
                case '1031':
                    $status_label = 'DSP初始化故障';
                    break;
                case '1032':
                    $status_label = '温度保护';
                    break;
                case '1033':
                    $status_label = '接地保护';
                    break;
                case '1034':
                    $status_label = '漏电流故障';
                    break;
                case '1035':
                    $status_label = '继电器故障';
                    break;
                case '1036':
                    $status_label = 'DSP_B故障';
                    break;
                case '1037':
                    $status_label = '直流分量过大';
                    break;
                case '1038':
                    $status_label = '12V欠压故障';
                    break;
                case '1039':
                    $status_label = '漏电流自检保护';
                    break;
                case '1040':
                    $status_label = '电弧自检保护';
                    break;
                case '1041':
                    $status_label = '电弧故障';
            }
        }
            if ($iv_type == 11) {
                switch ($status_hex) {
                    case '0000':
                        $status_label = '等待状态';
                        break;
                    case '0001':
                        $status_label = '开环运行';
                        break;
                    case '0002':
                        $status_label = '软起运行';
                        break;
                    case '0003':
                        $status_label = '并网运行';
                        break;
                    case '0004':
                        $status_label = '控制开关';
                        break;
                    case '1010':
                        $status_label = '电网过压';
                        break;
                    case '1011':
                        $status_label = '电网欠压';
                        break;
                    case '1012':
                        $status_label = '电网过频';
                        break;
                    case '1013':
                        $status_label = '电网欠频';
                        break;
                    case '1014':
                        $status_label = '电网阻抗过大';
                        break;
                    case '1015':
                        $status_label = '无电网';
                        break;
                    case '1016':
                        $status_label = '电网不平衡';
                        break;
                    case '1017':
                        $status_label = '电网频率抖动';
                        break;
                    case '1018':
                        $status_label = '电网过流';
                        break;
                    case '1020':
                        $status_label = '直流过压';
                        break;
                    case '1021':
                        $status_label = '直流母线过压';
                        break;
                    case '1022':
                        $status_label = '直流母线不均压';
                        break;
                    case '1023':
                        $status_label = '直流母线欠压';
                        break;
                    case '1024':
                        $status_label = '直流母线不均压';
                        break;
                    case '1025':
                        $status_label = '直流A路过流';
                        break;
                    case '1026':
                        $status_label = '直流B路过流';
                        break;
                    case '1027':
                        $status_label = '直流输入扰动';
                        break;
                    case '1030':
                        $status_label = '电网扰动';
                        break;
                    case '1031':
                        $status_label = 'DSP初始化故障';
                        break;
                    case '1032':
                        $status_label = '温度保护';
                        break;
                    case '1033':
                        $status_label = '接地保护';
                        break;
                    case "1034":
                        $status_label = '漏电流故障';
                        break;
                    case '1035':
                        $status_label = '继电器故障';
                        break;
                    case '1036':
                        $status_label = 'DSP_B故障';
                        break;
                    case '1037':
                        $status_label = '直流分量过大';
                        break;
                    case '1038':
                        $status_label = '12V欠压故障';
                        break;
                    case '1039':
                        $status_label = '漏电流自检保护';
                        break;
                    case '1040':
                        $status_label = '电弧自检保护';
                        break;
                    case '1041':
                        $status_label = '电弧故障';
                        break;
                }
            }
        return $status_label;
    }
}

